using Godot;
using Godot.Collections;
using System;

public class Entity : Node2D
{
    public String Name;
    public EntityData entityData;
    public override void _Ready()
    {

    }
    public Vector2 GetChunkLocation()
    {
        return (GlobalPosition / 16).Floor() / 16;
    }

    public static Entity LoadScene(String Name)
    {
        //"res://Tscn/ItemEntity.tscn"
        PackedScene ps = GD.Load<PackedScene>($"res://Tscn/{Name}.tscn");
        return ps.Instance<Entity>();
    }

    public Dictionary getDict()
    {
        Dictionary dict = new Dictionary();
        dict.Add("Name", Name);
        dict.Add("X", Position.x);
        dict.Add("Y", Position.y);
        return dict;
    }
    public String toJson()
    {
        return JSON.Print(getDict());
    }
    public Entity JsonTo(Dictionary dict)
    {
        Name = (String)dict["Name"];
        int x = dict["X"].ToInt();
        int y = dict["Y"].ToInt();
        return this;
    }
}
